package com.example.springprincle.component;

import com.example.springprincle.model.Doge;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Bean的生命周期
 */
@Component
public class BeanLifeConponent implements BeanNameAware {
    private Doge getDoge2;

    public BeanLifeConponent(){
        System.out.println("执行构造函数 ");
    }

    @Autowired
    public void setSingletonDog(Doge getDoge2){
        this.getDoge2 =getDoge2;
        System.out.println("执行setSingleton");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("setBeanName："+name);
    }
    @PostConstruct
    public void init(){
        System.out.println("执行postConstruct方法");
    }

    public void  use(){
        System.out.println("执行use方法");
    }
    @PreDestroy
    public void destroy(){
        System.out.println("执行destory");
    }
}
